package db;


import db.DTO.DTOAcidente;
import db.DTO.DTOFuncionario;
import java.sql.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

public class DAOFuncionario implements InterfaceDAO {

    public DAOFuncionario(){
    }
 
    public Collection recuperaRegistroComParametros(String sNome){
  
        String sql = "SELECT "+
                    "\"Matricula\", \"Nome\", \"Sexo\", \"Dt_admissao\", \"Funcao\","+
                    "\"CBO\", \"Setor\", \"Codigo_Area\", \"Codigo_Turma\", \"Codigo_Turno\", \"Chefe\""+
                     "FROM FUNCIONARIO WHERE upper(\"Nome\") LIKE upper(?)";
        List retorno = new ArrayList();
        
        DbConnect.getIntancDbConnect().conect();
        
        try{
            PreparedStatement pst = DbConnect.getIntancDbConnect().getConect().prepareStatement( sql );
            pst.setString(1, "%" + sNome + "%");
 
            ResultSet rs = pst.executeQuery();
            //Instancia os DTOS para o controle
            while( rs.next() ) { 
               retorno.add(new DTOFuncionario(rs.getString("Matricula"), rs.getString("Nome"), rs.getString("Sexo"),
                       rs.getString("Dt_admissao"), rs.getString("Funcao"), rs.getString("CBO"),rs.getString("Setor"),
                       rs.getInt("Codigo_Area"), rs.getInt("Codigo_Turma"), rs.getInt("Codigo_Turno"), rs.getString("Chefe")));
            }
            rs.close();
            pst.close();
        }
        catch ( SQLException e){
            System.err.println ("\ncxcError Menssage: " + e.getMessage());
        }
        DbConnect.getIntancDbConnect().closeConect();
        return retorno;
    }

    public Collection recuperaRegistroPorPK(int codigo) {
        throw new UnsupportedOperationException("Not supported yet.");
    }


    public void deleteRegistroById(int id) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void insertRegistro(DTOAcidente dtoAcidente) throws SQLException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void updateRegistro(DTOAcidente dtoAcidente, int codigo) throws SQLException {
        throw new UnsupportedOperationException("Not supported yet.");
    }
    
    
}
